package com.example.isoftservice.controller;

import com.example.isoftservice.pojos.Logs;
import com.example.isoftservice.service.LogsService;
import com.example.isoftservice.util.Result;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/*
 *系统日志相关接口
 */
@CrossOrigin
@RestController
@RequestMapping("/logs")
public class LogsController {
    @Resource
    private LogsService logsService;

    @GetMapping("/searchByPage")
    public Result<Map<String,Object>> searchByPage(@RequestParam(name = "pageNo",defaultValue = "1") Integer pageNo,
                                                   @RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize,
                                                    Logs logs) {
        Result<Map<String, Object>> result = new Result<>();
        result.setCode(0);
        result.setResult(logsService.searchByPage(pageNo,pageSize,logs));
        return result;
    }

    @PostMapping("/add")
    public  Result<Boolean> addLogs(Logs logs) {
        Result<Boolean> result = new Result<>();
        result.setCode(0);
        result.setResult(logsService.addLogs(logs));
        result.setMessage("增加");
        return result;
    }

    @PostMapping("/remove")
    public Result<Boolean> removeLogs(@RequestBody Logs logs) {
        Result<Boolean> result = new Result<>();
        result.setCode(0);
        result.setResult(logsService.removeLogs(logs.getIds()));
        result.setMessage("删除");
        return result;
    }

}
